"""
视图函数
"""
from django.http import HttpResponse

from common.captcha import Captcha
from common.utils import gen_captcha_text


def get_captcha(request):
    captcha_text = gen_captcha_text()
    image_bytes = Captcha.instance().generate(captcha_text)
    request.session['captcha'] = captcha_text.lower()
    return HttpResponse(image_bytes, content_type='image/png')
